

import javax.xml.ws.Provider;
import javax.xml.ws.Service;
import javax.xml.ws.ServiceMode;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.WebServiceProvider;
import javax.xml.ws.handler.MessageContext;

@SuppressWarnings("unchecked")
@WebServiceProvider
@ServiceMode(value = Service.Mode.PAYLOAD)
public class GenericController<T> implements Provider<T> {

	protected WebServiceContext wsContext;
	private String SUCCESS = "success";

	@Override
	public T invoke(T request) {
		MessageContext mc = wsContext.getMessageContext();
		String path = (String) mc.get(MessageContext.PATH_INFO);
		String method = (String) mc.get(MessageContext.HTTP_REQUEST_METHOD);
		if (method.equals("GET"))
			return get(mc);
		if (method.equals("POST"))
			return post(request, mc);
		if (method.equals("PUT"))
			return put(request, mc);
		if (method.equals("DELETE"))
			return delete(request, mc);
		else
			return null;
	}

	// Other methods not shown here

	public T get(MessageContext mc) {
		return (T) SUCCESS;
	}

	public T post(T request, MessageContext mc) {
		return (T) SUCCESS;
	}

	public T put(T request, MessageContext mc) {
		return (T) SUCCESS;
	}

	public T delete(T request, MessageContext mc) {
		return (T) SUCCESS;
	}

}
